import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# 假设df是你的DataFrame，包含score字段

df = pd.read_csv('secu_list.csv')

# 选择字段
selected_columns = ['m5', 'stk_fund1','stk_fund2','stk_fund3','stk_fund4','stk_fund5','stk_fund6','stk_fund7']
# selected_columns = ['m5', 'relative_strength' ]

df_selected = df[selected_columns]




# 计算相关性
correlation_matrix = df_selected.corr()

# 显示相关性矩阵
print(correlation_matrix)


# 选择要分析的score字段
score_columns =[  'stk_fund1','stk_fund2','stk_fund3','stk_fund4','stk_fund5','stk_fund6','stk_fund7']
# score_columns =[ 'score1','score2','score3','score4','score5','score6','score7', 'score8','score9','score10','score11','score12','score13','score14']

# 创建一个区间的列表
# bins = list(range(0, 101, 1))  # 创建从0到100的区间，间隔为10

bins = list(range(0, 11))  # 创建从0到10的整数列表
bins = [i * 0.1 for i in bins]  # 将每个整数转换为0.1的倍数


# 创建一个新的DataFrame来存储区间化的数据
interval_data = pd.DataFrame()

# 对每个score字段应用cut函数
for col in score_columns:
    interval_data[col] = pd.cut(df[col], bins, labels=False)

# 现在interval_data包含了每个score字段的区间编号

# 绘制每个score字段的分布情况
plt.figure(figsize=(12, 6))

for i, col in enumerate(score_columns, start=1):
    plt.subplot(3, 3, i)  # 创建一个3x3的子图网格
    sns.countplot(x=col, data=interval_data, order=range(10))  # 绘制计数图，并按顺序排列区间
    plt.xlabel(col)
    plt.ylabel('Count')
    plt.title(f'Distribution of {col}')
    plt.xticks(range(10), [f'{i * 10}-{(i + 1) * 10 - 1}' for i in range(10)])  # 设置x轴的标签为区间范围

plt.tight_layout()  # 调整子图之间的间距
plt.show()

